package com.controller;

import com.model.Role;
import com.service.RoleService;
import com.tool.ResponseMessage;
import com.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 编写者：王懿宸
 * 编写时间：2019-5-29
 * 类模块描述：查询及相关增删改
 */
@RestController(value = "/Role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value="/getStr")
    public String setRoleStr(String name){
        return "你输入的名字叫: "+name;
    }
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getOne")
    public Role getOne(int rid){
        return roleService.selectByPrimaryKey(rid);
    }
    /*查询数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/getIsBegin")
    public List<Role> getIsBegin(){
        System.out.println("调用角色全部类型接口");
        List<Role> listRole = roleService.getIsBegin();
        return listRole;
    }
    @CrossOrigin
    @RequestMapping(value = "/getAll")
    public ResponseMessage getAll(){
        System.out.println("调用角色全部信息");
        Map<String,List> map = new HashMap<>();
        map.put("list",roleService.getAll());
        return Result.success("200",map);
    }
    /*删除数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/delRole",method = RequestMethod.GET)
    public int delRole(Integer rid){
        return roleService.delRole(rid);
    }
    /*添加数据*/
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/addRole",method = RequestMethod.PUT)
    public int addRole(@RequestBody Role rolemodel){
        if (rolemodel!=null){

        }
        else
            {}
        return roleService.insertRole(rolemodel);
    }
    @CrossOrigin/*跨越访问*/
    @RequestMapping(value = "/updateRole",method = RequestMethod.PUT)
    public int updateRole(@RequestBody Role rolemodel ){
        if (rolemodel != null){

        }else
        {}
            return roleService.updateRole(rolemodel);
    }
}
